/**
 * @author 徐楠
 * @date 2022/4/12 19:24
 * @version 1.0
 */

package com.xunan.likou;

public class NumArray {
    private int[] nums;

    public NumArray(int[] nums) {
        this.nums = nums;
    }


    // 查询 [left, right] 之间的元素和
    public int sumRange(int left, int right) {
        int result = 0;
        for (int i = left; i <= right; i++) {
            result += nums[i];
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {-2, 0, 3, -5, 2, -1};
        NumArray numArray = new NumArray(nums);
        int result = numArray.sumRange(2, 5);
        System.out.println(result);
    }
}
